package com.atguigu.controller;

import com.atguigu.dto.product.CategoryBrandDto;
import com.atguigu.entity.product.Brand;
import com.atguigu.entity.product.CategoryBrand;
import com.atguigu.service.CategoryBrandService;
import com.atguigu.vo.common.Result;
import com.atguigu.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "产品分类")
@RestController
@RequestMapping("/product/categoryBrand")
public class CategoryBrandController {
    @Autowired
    private CategoryBrandService categoryBrandService;

    @Operation(summary = "查找产品分类下的品牌")
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    public Result findBrandByCategoryId(@PathVariable Long categoryId) {
        List<Brand> brandList = categoryBrandService.findBrandByCategoryId(categoryId);
        return Result.build(brandList, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加分类下的品牌")
    @PostMapping("submit")
    public Result submit(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.submit(categoryBrand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "分类品牌条件分页查询")
    @GetMapping("/page/{current}/{limit}")
    public Result page(@PathVariable Integer current, @PathVariable Integer limit,@RequestParam CategoryBrandDto categoryBrandDto) {
        PageInfo<CategoryBrand> categoryBrandList = categoryBrandService.page(current, limit,categoryBrandDto);
        return Result.build(categoryBrandList, ResultCodeEnum.SUCCESS);
    }
}
